<template>
  <div class="index">
    <div class="index-child">
      <p class="username" @click="goIndex">首页</p>
      <i></i>
      <p class="username" @click="goCenter">个人中心</p>
      <i></i>
      <p class="quit" @click="logOut">退出</p>
    </div>
  </div>
</template>
<script>
import {logOut} from '../../api/ajax'
export default {
  name: 'index',
  methods: {
    goCenter () {
      this.$router.push({
        name: 'personalCenter'
      })
    },
    goIndex(){
      this.$router.push({
        name: 'index'
      })
    },
    logOut () {
      this.$confirm('此操作将退出登录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        logOut().then(res => {
          console.log(res);
          if(res.data.code === 1) {
            localStorage.clear();
            sessionStorage.clear();
            this.$message.success('退出成功')
            this.$router.push({
              path: '/'
            })
          }
        })
      }).catch(() => {
      });
      
    }
  }
}
</script>
<style scoped>
  .index{
    width:100%;
    height:40px;
    background:#f2f2f2;
  }
  .index-child{
    width:1200px;
    margin:0 auto;
    height:40px;
    display:flex;
    align-items:center;
    justify-content: flex-end;
  }
  .index-child .username,.index-child .quit{
    font-size: 14px;
    line-height: 14px;
    color: #333;
    cursor: pointer;
  }
  .index-child i{
    width: 1px;
    height: 14px;
    background: #333;
    margin:  0 10px;
  }
</style>
